<?php

/**
 * Subject form.
 *
 * @package    wiki
 * @subpackage form
 * @author     Elmaho
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class SubjectForm extends BaseSubjectForm
{
  public function configure()
  {
  	
  	$choices = DomainTable::getListArbo();
	$entitePere = new sfWidgetFormSelect(array('choices' => $choices));
	$this->widgetSchema['domain_id'] = $entitePere;
	$this->validatorSchema['domain_id'] = new sfValidatorInteger(array('required' => true));
	
  	$this->widgetSchema ['title_sjt'] = new sfWidgetFormInputText();
  	$this->widgetSchema ['summary_sjt'] = new sfWidgetFormTextareaTinyMCE(array(
										  'width'  => 550,
										  'height' => 350,
										  'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
										));
  	$this->widgetSchema ['article_sjt'] = new sfWidgetFormTextareaTinyMCE(array(
										  'width'  => 550,
										  'height' => 350,
										  'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',
										));
	$this->widgetSchema ['read_times'] = new sfWidgetLabel(array('text' => $this->getObject()->getReadTimes() ? $this->getObject()->getReadTimes() : 0));
	$this->widgetSchema ['updated_at'] = new sfWidgetLabel(array('text' => $this->getObject()->getUpdatedAt('d/m/Y')));
	$this->widgetSchema ['link_sjt'] = new sfWidgetFormInputFileEditable(array(
																		      'label'     => 'Company logo',
																		      'file_src'  => sfConfig::get('sf_upload_dir').'/papers/'.$this->getObject()->getLinkSjt(),
																		      'is_image'  => false,
																		      'edit_mode' => !$this->isNew(),
																		      'template'  => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>',
																		    ));
																		    
     $this->validatorSchema['link_sjt'] = new sfValidatorFile(array(
      'required'   => false,
      'path'       => sfConfig::get('sf_upload_dir').'/papers',
//      'mime_types' => 'web_images',
    ));
	
	$this->validatorSchema['updated_at'] = new sfValidatorPass();
	$this->validatorSchema['created_at'] = new sfValidatorPass();
  }
  
  public function setDomain($idp){
  	$this->widgetSchema['domain_id']->setDefault("$idp");
  }
  
  public function doSave($con = null)
  {
  	parent::doSave($con);
  	
  	$as = new AuthorSubject();
  	$as->setSubject($this->getObject());
  	$as->setPerson(sfContext::getInstance()->getUser()->getPerson());
  	$as->save();
  }
  
}
